home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 25 / AACD 25.iso / AACD / Magazine / Online / QMail / source / qsutil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-25  |  1.4 KB  |  54 lines

  1. #include "stralloc.h"
  2. #include "readwrite.h"
  3. #include "substdio.h"
  4. #include "qsutil.h"
  5. #include "error.h"
  6.  
  7. static stralloc foo = {0};
  8.  
  9. static char errbuf[1];
  10. static struct substdio sserr = SUBSTDIO_FDBUF(write,0,errbuf,1);
  11.  
  12. void logsa(sa) stralloc *sa; {
  13.  substdio_putflush(&sserr,sa->s,sa->len); }
  14. void log1(s1) char *s1; {
  15.  substdio_putsflush(&sserr,s1); }
  16. void log2(s1,s2) char *s1; char *s2; {
  17.  substdio_putsflush(&sserr,s1);
  18.  substdio_putsflush(&sserr,s2); }
  19. void log3(s1,s2,s3) char *s1; char *s2; char *s3; {
  20.  substdio_putsflush(&sserr,s1);
  21.  substdio_putsflush(&sserr,s2);
  22.  substdio_putsflush(&sserr,s3); }
  23. void log5(s1,s2,s3,s4,s5) char *s1; char *s2; char *s3; char *s4; char *s5; {
  24.  substdio_putsflush(&sserr,s1);
  25.  substdio_putsflush(&sserr,s2);
  26.  substdio_putsflush(&sserr,s3);
  27.  substdio_putsflush(&sserr,s4);
  28.  substdio_putsflush(&sserr,s5); }
  29. void nomem() { log1("alert: out of memory, sleeping...\n"); sleep(10); }
  30.  
  31. void pausedir(dir) char *dir;
  32. { log5("alert: unable to opendir ",dir," (",strerror(errno),"), sleeping...\n"); sleep(10); }
  33.  
  34. static int issafe(ch) char ch;
  35. {
  36.  if (ch == '%') return 0; /* general principle: allman's code is crap */
  37.  if (ch < 33) return 0;
  38.  if (ch > 126) return 0;
  39.  return 1;
  40. }
  41.  
  42. void logsafe(s) char *s;
  43. {
  44.  int i;
  45.  while (!stralloc_copys(&foo,s)) nomem();
  46.  for (i = 0;i < foo.len;++i)
  47.    if (foo.s[i] == '\n')
  48.      foo.s[i] = '/';
  49.    else
  50.      if (!issafe(foo.s[i]))
  51.        foo.s[i] = '_';
  52.  logsa(&foo);
  53. }
  54.